﻿/*	
	stencil - action script 3 isometric game engine.

	http://code.google.com/p/stencilas3/
	
	Copyright (c) 2010 Max Zhuravkov, All Rights Reserved.

	Permission is hereby granted, free of charge, to any person obtaining a copy of
	this software and associated documentation files (the "Software"), to deal in
	the Software without restriction, including without limitation the rights to
	use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
	of the Software, and to permit persons to whom the Software is furnished to do
	so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
package stencil.core.engine.scene 
{
	import adobe.utils.CustomActions;
	import flash.events.EventDispatcher;
	import flash.geom.Rectangle;
	import stencil.core.engine.ICameraModel;
	import stencil.core.engine.IGrid;
	import stencil.core.engine.IMapGraph;
	import stencil.core.engine.Position;
	import stencil.core.engine.IMapArea;
	import stencil.core.engine.MapNode;
	import stencil.core.engine.ISceneObject;
	import stencil.core.engine.TileSettings;
	import stencil.core.errors.NotImplementedMethodError;
	
	/**
	 * ...
	 * @author Max Zhuravkov
	 */
	public class AbstractSceneModel extends EventDispatcher implements ISceneModel {
		
		private var _cameras:Array = [];
		
		private var _objectGrid:IGrid;
		
		private var _tileGrid:IGrid;
		
		protected var flagDataChanged:Boolean = false;
		
		//----------------------------------------------------------------
		// Constructor
		//----------------------------------------------------------------
		
		public function AbstractSceneModel() {
			
		}
		
		//----------------------------------------------------------------
		// Public properties
		//----------------------------------------------------------------
		
		/**
		 * @inheritDoc
		 */
		public function set objectGrid(value:IGrid):void {
			if (this._objectGrid == value) {
				return;
			}
			this._objectGrid = value;
		}
		
		public function get objectGrid():IGrid {
			return this._objectGrid;
		}
		
		/**
		 * @inheritDoc
		 */
		public function set tileGrid(value:IGrid):void {
			if (this._tileGrid == value) {
				return;
			}
			this._tileGrid = value;
		}
		
		public function get tileGrid():IGrid {
			return this._tileGrid;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get boundaries():Rectangle {
			throw new NotImplementedMethodError("get boundaries")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get globalBoundaries():Rectangle {
			throw new NotImplementedMethodError("get globalBoundaries")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function set tileSettings(value:TileSettings):void {
			throw new NotImplementedMethodError("set tileSettings")
			
		}
		
		/**
		 * @inheritDoc
		 */
		public function get tileSettings():TileSettings {
			throw new NotImplementedMethodError("get tileSettings")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function set mapGraph(value:IMapGraph):void {
			throw new NotImplementedMethodError("set mapGraph")
		}
		
		/**
		 * @inheritDoc
		 */
		public function get mapGraph():IMapGraph {
			throw new NotImplementedMethodError("get mapGraph")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get sceneNodes():Array {
			throw new NotImplementedMethodError("get sceneNodes")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get lists():Array {
			throw new NotImplementedMethodError("get lists")
			return null;
		}

		//----------------------------------------------------------------
		// Public methods
		//----------------------------------------------------------------
		
		/**
		 * @inheritDoc
		 */
		public function init():void {
			throw new NotImplementedMethodError("init")
		}
		
		
		/**
		 * @inheritDoc
		 */
		public function getSceneNode(p:Position):ISceneNode {
			throw new NotImplementedMethodError("getNodeAt")
			return null;
		}
		
		
		/**
		 * @inheritDoc
		 */
		public function createList(name:String, filter:Function = null):Array {
			throw new NotImplementedMethodError("createList")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getList(name:String):Array {
			throw new NotImplementedMethodError("getList")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function hasList(name:String):Boolean {
			throw new NotImplementedMethodError("hasList")
			return false;	
		}
		
		/**
		 * @inheritDoc
		 */
		public function removeList(name:String):void {
			throw new NotImplementedMethodError("removeList")
		}
		
		/**
		 * @inheritDoc
		 */
		public function removeLists():void {
			throw new NotImplementedMethodError("removeLists")
		}
		
		
		/**
		 * Adds object to scene.
		 * 
		 * @param	object	the object.
		 * 
		 * @eventType	stencil.core.engine.events.SceneUpdateEvent.STN_ADD_OBJECT
		 * 
		 * @return	if object was successfully added returns 'true'. when as the result of add operation this given object 
		 * was removed from scene (it was outside scene boundaries at that time) this method returns 'false'.
		 */
		public function addObject(object:ISceneObject):Boolean {
			throw new NotImplementedMethodError("addObject")
			return false;
		}
		
		
		/**
		 * Removes the object from scene.
		 * 
		 * @param	object	the scene object.
		 * 
		 * @eventType	stencil.core.engine.events.SceneUpdateEvent.STN_REMOVE_OBJECT
		 * 
		 * @return	'true' when an object was successfully removed and 'false' otherwise.
		 */
		public function removeObject(object:ISceneObject):Boolean {
			throw new NotImplementedMethodError("removeObject")
			return false;
		}
		
		
		/**
		 * @inheritDoc
		 */
		public function updateObject(object:ISceneObject):Boolean {
			throw new NotImplementedMethodError("updateObject")
			return false;
		}
		
		/**
		 * @inheritDoc
		 */
		public function containsObject(object:ISceneObject):Boolean {
			throw new NotImplementedMethodError("containsObject");
			return false;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getObject(id:String):ISceneObject {
			throw new NotImplementedMethodError("getObject")
			return null;
		}

		/**
		 * @inheritDoc
		 */
		public function getObjects(rect:Rectangle, filter:Function = null):Array {
			throw new NotImplementedMethodError("getObjects")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getObjectsAt(p:Position, filter:Function = null):Array {
			throw new NotImplementedMethodError("getObjectsAt")
			return null;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getArea(rect:Rectangle, filter:Function = null):IMapArea {
			throw new NotImplementedMethodError("getArea")
			return null;
		}
		
		public function dispose():void {
			
		}
		
		//----------------------------------------------------------------
		// Public methods
		//----------------------------------------------------------------
		
		public final function attachCamera(camera:ICameraModel):void{
			if (this._cameras.indexOf(camera) == -1) {
				this._cameras.push(camera);
				this.cameraAttached(camera);
			}
		}
		
		public final function deatachCamera(camera:ICameraModel):void{
			var index:int = this._cameras.indexOf(camera);
			if (index >= 0) {
				this._cameras.splice(index, 1);
				this.cameraDetached(camera);
			}
		}
		
		public function getVisibleArea(camera:ICameraModel):IMapArea {
			throw new NotImplementedMethodError("getVisibleArea");
			return null;
		}
		
		public function update(time:Number):void {
			this.updateScene(time);
			this.flagDataChanged = false;
		}
		
		//----------------------------------------------------------------
		// Protected properties
		//----------------------------------------------------------------
		
		protected function cameraAttached(camera:ICameraModel):void {
			throw new NotImplementedMethodError("cameraAttached");
		}
		
		protected function cameraDetached(camera:ICameraModel):void {
			throw new NotImplementedMethodError("cameraDetached");
		}
		
		protected function updateScene(time:Number):void {
			throw new NotImplementedMethodError("updateScene");
		}
		
		protected final function get cameras():Array {
			return this._cameras;
		}
		
		
	}

}